`
https://leetcode.cn/problems/watering-plants-ii/
`

/**
 * @param {number[]} plants
 * @param {number} capacityA
 * @param {number} capacityB
 * @return {number}
 */
var minimumRefill = function (plants, capacityA, capacityB) {
  let left = 0, right = plants.length - 1
  let a = capacityA, b = capacityB
  let res = 0
  while (left < right) {
    // Alice 浇水
    if (a < plants[left]) {
      a = capacityA
      res++
    }
    a -= plants[left]
    left++

    // Bob 浇水
    if (b < plants[right]) {
      b = capacityB
      res++
    }
    b -= plants[right]
    right--
  }
  if (left === right && Math.max(a, b) < plants[left]) {
    res++
  }
  return res
};